package fei.zhou.userservice.business.controller;

import fei.zhou.userservice.business.bean.User;
import fei.zhou.userservice.business.service.UserService;
import fei.zhou.userservice.config.IpConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.net.InetAddress;
import java.net.UnknownHostException;

@RestController
@RequestMapping("/user")
@RefreshScope //刷新配置
public class UserController {
    
    @Autowired
    private UserService userService;


    @Autowired
    IpConfiguration ipConfiguration;



    @Value("${zhou.fei.name}")
    private String name;

    @GetMapping("/{id}")
    public User queryById(@PathVariable Long id) throws UnknownHostException {
        InetAddress   address = InetAddress.getLocalHost();
        User user = userService.queryById(id);
        user.setNote("ip："+address.getHostAddress()+"--->端口："+ipConfiguration.getPort()+"--->zhou.fei.name："+name);
        return user;
    }
}
